package com.yxq.mdt.app.modules.login.ui;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import androidx.annotation.Nullable;

import com.blankj.utilcode.util.ToastUtils;
import com.yxq.mdt.app.R;
import com.yxq.mdt.app.base.BaseActivity;
import com.yxq.mdt.app.modules.login.bean.UserBean;
import com.yxq.mdt.app.modules.login.model.LoginModel;
import com.yxq.mdt.app.modules.login.presenter.ILoginContract;
import com.yxq.mdt.app.modules.login.presenter.LoginPresenter;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author L
 * @time
 * @describe 忘记密码-重置密码
 */
public class ResetPasswordActivity extends BaseActivity<LoginPresenter> implements ILoginContract.View {

    @BindView(R.id.login_et_account)
    EditText pwdEditText;
    @BindView(R.id.login_et_pwd)
    EditText rePwdEditText;

    @Override
    public int getLayoutId() {
        return R.layout.activity_reset_password;
    }

    @Override
    public void initView() {
        mPresenter = new LoginPresenter(this, new LoginModel());
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {

    }

    @OnClick({R.id.login_btn_login})
    public void onClicked(View view) {
        switch (view.getId()) {
            case R.id.login_btn_login:
                forget();
                break;
        }
    }

    private void forget() {

        if (pwdEditText.getText().toString().length() == 0) {
            ToastUtils.showShort("请输入密码");
            return;
        }
        if (rePwdEditText.getText().toString().length() == 0) {
            ToastUtils.showShort("请输入确认密码");
            return;
        }

        if (!rePwdEditText.getText().toString().equals(pwdEditText.getText().toString())) {
            ToastUtils.showShort("两次输入的密码不一致");
            return;
        }
        showLoadingDialog();
        mPresenter.forget(getIntent().getStringExtra("phone"), pwdEditText.getText().toString(), rePwdEditText.getText().toString(), 2, getIntent().getStringExtra("code"));
    }

    @Override
    public void onLoginSuccess(UserBean userBean) {

    }

    @Override
    public void onLoginFailed(String error) {

    }

    @Override
    public void onVerifyCodeSuccess(String info) {

    }

    @Override
    public void onVerifyCodeFailed(String error) {

    }

    @Override
    public void onRegisterSuccess(String userBean) {
        hideLoadingDialog();
        ToastUtils.showShort("修改密码成功");
        finish();
    }

    @Override
    public void onRegisterFailed(String error) {
        hideLoadingDialog();
        ToastUtils.showShort(error);
    }

    @Override
    public void onBindPhoneSuccess(String userBean) {

    }

    @Override
    public void onBindPhoneFailed(String error) {

    }
}
